import {
	observable,
	action,
	computed,
} from 'mobx';
import {
	WeaLocaleProvider,
} from 'ecCom';
import {
	WeaForm,
	WeaTableNew
} from 'comsMobx';
import {
	message,
	Button,
	Modal,
} from 'antd';
import * as api from '../apis/tax';
const getLabel = WeaLocaleProvider.getLabel;
const confirm = Modal.confirm;
const {
	TableStore
} = WeaTableNew;

class HrmTax {
	@observable cPage = 'main';

	TAXDEDUCTIONITEMS = ['childEducation', 'continualEducation', 'loan', 'rent', 'supportOlder']; //专项附加扣除填报

	BASICINFOITEMS = ['personalInfo', 'familyMember']; //基本信息

	get SEARCHGROUPS() {
		return [{
			title: getLabel(505832, '基本信息'),
			MENUS: [{
				icon: <span class="icon-coms02-Personal-information">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span>
                </span>,
				label: getLabel(505833, '个人信息'),
				onMenuClick: () => this.handleMenuClick('personalInfo')
			}, {
				icon: <span class="icon-coms02-Family-members">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>,
				label: getLabel(505834, '家庭成员'),
				onMenuClick: () => this.handleMenuClick('familyMember')
			}]
		}, {
			title: getLabel(505835, '专项附加扣除填报'),
			MENUS: [{
				icon: <span class="icon-coms02-Childrens-education">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span>
                </span>,
				label: getLabel(505836, '子女教育'),
				onMenuClick: () => this.handleMenuClick('childEducation')
			}, {
				icon: <span class="icon-coms02-Continuing-Education">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span><span class="path6"></span>
                </span>,
				label: getLabel(505837, '继续教育'),
				onMenuClick: () => this.handleMenuClick('continualEducation')
			}, {
				icon: <span class="icon-coms02-Loan-interest">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span>
                </span>,
				label: getLabel(505838, '住房贷款利息'),
				onMenuClick: () => this.handleMenuClick('loan')
			}, {
				icon: <span class="icon-coms02-Housing-rent">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span><span class="path6"></span><span class="path7"></span>
                </span>,
				label: getLabel(505839, '住房租金'),
				onMenuClick: () => this.handleMenuClick('rent')
			}, {
				icon: <span class="icon-coms02-Old-man">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span>
                </span>,
				label: getLabel(505840, '赡养老人'),
				onMenuClick: () => this.handleMenuClick('supportOlder')
			}]
		}]
	};

	get TOP() {
		return {
			showDropIcon: true,
			iconBgcolor: '#217346',
			icon: <i className='icon-coms-hrm'/>,
			title: getLabel(505841, '个税专项附加扣除信息填报')
		}
	}

	@computed get breadcrumb() {
		let a;

		const f = {
			name: getLabel(505842, '信息填报'),
			onClick: () => {
				this.cPage = 'main';
				this.resetStepIndex();
				this.renewForm();
			}
		};

		switch (this.cPage) {
			case 'main':
				a = [];
				break;
			case 'personalInfo':
				const {
					isEdit
				} = this.oneForm;

				if (isEdit === '0') {
					a = [f, {
						name: getLabel(505833, '个人信息'),
					}]
				} else {
					a = [{
						name: getLabel(505843, '个税专项附加扣除信息采集'),
						onClick: () => {
							this.cPage = 'main'
						}
					}, {
						name: getLabel(505844, '基本信息填报'),
					}]
				}
				break;
			case 'familyMember':
				a = [f, {
					name: getLabel(505834, '家庭成员'),
				}]
				break;
			case 'childEducation':
				a = [f, {
					name: getLabel(505836, '子女教育'),
				}]
				break;
			case 'continualEducation':
				a = [f, {
					name: getLabel(505837, '继续教育'),
				}]
				break;
			case 'loan':
				a = [f, {
					name: getLabel(505838, '住房贷款利息'),
				}]
				break;
			case 'rent':
				a = [f, {
					name: getLabel(505839, '住房租金'),
				}]
				break;
			case 'supportOlder':
				a = [f, {
					name: getLabel(505840, '赡养老人'),
				}]
				break;
		}

		return a;
	}

	@computed get pageLoading() {
		const {
			comsWeaTableStore
		} = this.table;

		let loading;
		const pageHasTable = this.pageHasTable();

		const pageHasOneForm = this.pageHasOneForm();

		const pageHasTwoForm = this.pageHasTwoForm();

		const tableLoading = comsWeaTableStore.loading;

		const oneFormLoading = this.oneForm.loading;

		const twoFormLoading = this.twoForm.loading;

		if (pageHasTable && !pageHasOneForm) {
			loading = tableLoading;
		}

		if (pageHasTable && pageHasOneForm) {
			loading = tableLoading || oneFormLoading;
		}

		//只包含个人信息表单
		if (pageHasOneForm && !pageHasTwoForm) {
			loading = oneFormLoading;
		}

		//不仅包含个人信息表单，也包含条件表单
		if (pageHasOneForm && pageHasTwoForm) {
			loading = oneFormLoading || twoFormLoading;
		}
		return loading;
	}

	//页面中是否包含列表
	pageHasTable = () => {
		const {
			currentIndex
		} = this.step;

		if (['familyMember', 'recordInfo', 'queryDeductionMoney'].includes(this.cPage)) {
			return true
		}
		if (['childEducation', 'supportOlder'].includes(this.cPage) && currentIndex === 1) {
			return true
		}
	}

	pageHasOneForm = () => {
		const {
			currentIndex
		} = this.step;

		if (this.cPage === 'personalInfo') {
			return true;
		}
		if (this.TAXDEDUCTIONITEMS.includes(this.cPage)) {
			return true;
		}
	}

	pageHasTwoForm = () => {
		const {
			currentIndex
		} = this.step;

		if (this.cPage === 'loan') {
			return true;
		}
		if (this.cPage === 'continualEducation' && currentIndex === 1) {
			return true;
		}
		if (this.cPage === 'loan' && currentIndex < 2) {
			return true;
		}
		if (this.cPage === 'rent' && currentIndex === 1) {
			return true;
		}
	}


	@observable tConf = [];
	@observable rConf = [];

	@action getRightMenu = (isEdit) => {
		const params = {};
		if (this.cPage === 'personalInfo') {
			if (isEdit !== undefined) {
				Object.assign(params, {
					edit: isEdit
				});
			}
		}
		if (this.TAXDEDUCTIONITEMS.includes(this.cPage)) {
			Object.assign(params, {
				step: this.step.currentIndex + 1
			});
		}
		api.getRightMenu(this.cPage, params).then(data => {
			const {
				btnMenu
			} = data;

			const {
				tConf,
				rConf
			} = this.filter(btnMenu);

			this.tConf = tConf;
			this.rConf = rConf;
		}, error => {})
	}


	filter = (datas) => {
		let tConf, rConf;
		tConf = datas.filter(item => {
			var bool = false;
			['isTop', 'isBatch'].forEach(prop => {
				const b = parseInt(item[prop]);
				if (b) {
					bool = true
				}
			});

			return bool
		})

		rConf = datas;

		return {
			tConf,
			rConf
		}
	}

	@computed get topButtons() {
		if (['main', 'recordInfo', 'queryDeductionMoney'].includes(this.cPage)) {
			return [];
		}

		return this.tConf.map((item, index) => {
			const {
				menuFun,
				menuName
			} = item;

			return (
				<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@y9umoz@${index}`} 
					type="primary" 
					disabled={this.getDisabled(menuFun) } 
					onClick={() => this[menuFun]()}
				>
					{menuName}
				</Button>
			)
		});
	}

	@computed get dropMenuDatas() {
		if (['main', 'recordInfo', 'queryDeductionMoney'].includes(this.cPage)) {
			return [];
		}
		return this.rConf.map((item, index) => {
			const {
				menuFun,
				menuName,
				menuIcon
			} = item;

			return {
				key: index.toString(),
				disabled: this.getDisabled(menuFun),
				icon: <i className={`${menuIcon}`} />,
				content: menuName,
				onClick: () => this[menuFun]()
			}
		});
	}

	//编辑、保存个人信息表单CALLBACK
	operatePersonalForm = (isEdit) => {
		this.controlUnderline(isEdit);
		this.getRightMenu(isEdit);
		this.renewForm();
		this.formType = 'personalInfo';
		this.useFormType = 'forward';
		this.getForm(isEdit);
	}

	//编辑个人信息表单
	doEdit = () => {
		this.operatePersonalForm('1');
	}

	//保存个人信息表单
	doSave = () => {
		//表单验证通过后执行的逻辑
		const callback = () => {
			const result = this.validateCertainField();
			if (!result) {
				return
			}
			this.saveForm('oneForm', () => {
				this.operatePersonalForm('0');
			});
		}

		this.validateForm('oneForm', callback);
	}

	//返回
	doCancel = () => {
		this.operatePersonalForm('0');
	}

	//新建家庭成员
	doCreate = () => {
		this.defineDialogTitle(getLabel(505845, '新建家庭成员'));
		this.openDialog();
		this.renewForm();
		this.useFormType = 'forward';
		this.editingDataId = '';
		this.formType = '';
		this.getForm();
	}

	//上一步
	preStep = () => {
		const {
			currentIndex
		} = this.step;

		const logic = (val, callback) => {
			this.changeStepComponentState(false);
			this.getRightMenu();
			this.renewForm();
			this.useFormType = 'forward';
			this.getForm(val, callback);
		}

		if (currentIndex === 2) {
			const callback = () => {
				if (this.pageHasTable()) {
					this.getSearchList();
				}
				if (['continualEducation', 'loan', 'rent'].includes(this.cPage)) {
					this.useFormType = 'forward';
					this.declareYear = '';
					this.getForm();
				}
			}
			logic('', callback);
		} else if (currentIndex === 1) {
			this.formType = 'personalInfo';
			let callback;
			if (this.cPage === 'loan') {
				callback = () => {
					this.getForm()
				}
			}
			logic('0', callback);
		}

	}

	//下一步
	nextStep = () => {
		const {
			currentIndex
		} = this.step;

		const logic = (val, callback) => {
			this.changeStepComponentState(true);
			this.getRightMenu();
			this.renewForm();
			this.useFormType = 'forward';
			this.getForm(val, callback);
		}

		if (currentIndex === 0) {
			const callback = () => {
				const pageHasTable = this.pageHasTable();
				if (pageHasTable) {
					this.getSearchList();
				}
				if (['continualEducation', 'loan', 'rent'].includes(this.cPage)) {
					this.useFormType = 'forward';
					this.getForm();
				}
			};

			const _callback = callback;

			if (this.cPage === 'loan') {
				const callback = () => {
					const callback = () => {
						logic('', _callback);
					}
					this.saveForm('twoForm', callback);
				}
				this.validateForm('twoForm', callback)
			} else {
				this.checkInfo(() => logic('', callback));
			}
		} else if (currentIndex === 1) {
			const getCallBack = (cPage) => {
				if (['childEducation', 'supportOlder'].includes(cPage)) {
					return () => {
						if (this.isEmptyTable()) {
							message.warning(this.getWarningInfo());
						} else {
							this.formType = '';
							let callback;
							if (this.cPage === 'supportOlder') {
								callback = this.getTableEditInfo;
							}
							logic('', callback);
						}
					}
				}
				if (['loan', 'rent'].includes(cPage)) {
					return () => {
						const callback = () => {
							const callback = () => {
								this.formType = '';
								logic();
							};
							const {
								verificationId,
								rentType,
								verificationType,
							} = this.twoForm.form.getFormParams();

							if (rentType === '1' && verificationType === '1' && !this.testVerificationId(verificationId)) {
								message.warning(getLabel(518967, '居民身份证件号不正确！'));
								return
							}
							this.saveForm('twoForm', callback);

						};
						this.setNoNeedValidateFields();
						this.validateForm('twoForm', callback)
					}
				}
			}

			const callback = getCallBack(this.cPage);

			this.validateForm('oneForm', callback);
		}
	}

	checkInfo = (callback) => {
		api.checkInfo().then(data => {
			const {
				status,

			} = data;

			if (status === '1') {
				callback && callback();
			} else {
				message.warning(data.message);
			}
		});
	}

	//完成
	finish = () => {
		let callback;
		if (this.cPage === 'continualEducation') {
			callback = () => {
				const callback = () => {
					const callback = () => {
						const callback = () => {
							this.onTabChange('1');
						}
						this.saveForm('twoForm', callback);
					}
					this.validateMore(callback);
				}
				this.validateForm('twoForm', callback);
			}
		} else {
			callback = () => {
				const callback = () => {
					const callback = (datas) => {
						const {
							spouseNotFound
						} = datas;
						if (spouseNotFound === '1') {
							const callback = () => {
								this.defineDialogTitle(getLabel(505845, '新建家庭成员'));
								this.openDialog();
								this.useFormType = 'forward';
								this.getForm();
							}
							this.showConfirm(getLabel(505874, '请填写配偶信息！'), callback);
							return;
						}
						this.onTabChange('1');
					}
					this.saveForm('oneForm', callback, true);
				}
				if (this.cPage === 'supportOlder') {
					const {
						form
					} = this.oneForm, {
						onlyChild,
						cost,
					} = form.getFormParams();

					const isNeedValidateTable = () => {
						return onlyChild === '2';
					}
					if (isNeedValidateTable()) {
						if (cost > 1000) {
							message.warning(getLabel(506246, '非独生子女,本年度月扣除金额不得超过1000！'));
							return;
						}
						this.validateTableDatas(callback);
					} else {
						callback();
					}
				} else {
					callback();
				}
			}
		}
		this.setNoNeedValidateFields();
		this.validateForm('oneForm', callback);
	}

	getWarningInfo = () => {
		if (this.cPage === 'childEducation') {
			return getLabel(505846, '子女教育信息不能为空！');
		}
		if (this.cPage === 'supportOlder') {
			return getLabel(505847, '被赡养人信息不能为空！');
		}
	}

	@action changeStepComponentState = (isIncrease) => {
		if (isIncrease) {
			this.step.currentIndex++; //切换页面时，需要重置该变量
		} else {
			this.step.currentIndex--;
		}

		const {
			currentIndex,
			items,
		} = this.step;

		items.forEach((item, index) => {
			if (index < currentIndex) {
				Object.assign(item, {
					status: 'finish'
				});
			} else if (index === currentIndex) {
				Object.assign(item, {
					status: 'process'
				});
			} else {
				Object.assign(item, {
					status: 'wait'
				});
			}
		});
	}

	//批量删除
	doDelete = () => {
		const {
			comsWeaTableStore
		} = this.table, {
			selectedRowKeys
		} = comsWeaTableStore;

		const callback = () => {
			const params = {
				ids: selectedRowKeys.toString(),
			};
			this.delLogic(params);
		}
		const info = `${getLabel('385625', '确定要删除选择的记录吗？')}${getLabel(505848,'该记录可能会影响已填报信息！')}`;
		this.showConfirm(info, callback);
	}

	//确认是否删除
	//接收两个参数：是否是批量删除、确认删除后执行的回调函数
	showConfirm = (info, callback) => {
		confirm({
			title: getLabel('131329', '信息确认'),
			content: info,
			okText: getLabel('33703', '确定'),
			cancelText: getLabel('32694', '取消'),
			onOk() {
				callback && callback();
			},
			onCancel() {
				return false;
			},
		});
	}

	//执行删除任务的具体逻辑
	delLogic = (params) => {
		api.del(this.cPage, params).then(data => {
			const {
				status
			} = data;

			if (status === '1') {
				message.success(getLabel(506026, '删除成功'));
				this.getSearchList();
			} else {
				message.warning(getLabel(83473, '删除失败'));
			}
		});
	}

	//保存表单分两种情况：保存页面表单、保存弹框内的表单
	//参数formType为要保存表单的类型、 callback为这两种情况保存成功后，具体执行的逻辑
	saveForm = (formType, callback, canSaveFailOperateCallback) => {
		const {
			form
		} = this[formType];

		//后端默认取当前登录人员的id，因此这里不需要传人员id。
		const params = {
			...form.getFormParams(),
		};

		const additionalParams = this.getCallSaveApiAdditionalParams()

		if (additionalParams) {
			Object.assign(params, additionalParams);
		}

		api.save(this.cPage, params, this.step.currentIndex, this.isSubDialogVisible, this.isMainDialogVisible, this.formType).then(data => {
			const {
				status,
				id,
			} = data;

			if (status === '1') {
				message.success(getLabel(505849, '保存成功'));
				if (id) {
					Object.assign(this.otherDatas, {
						spouseId: id
					});
				}
				callback && callback(data);
			} else {
				canSaveFailOperateCallback && callback && callback(data);
				message.warning(data.message);
			}
		}, error => {})
	}

	//获取保存接口除了表单参数之外的其他参数
	getCallSaveApiAdditionalParams = () => {
		const {
			currentIndex
		} = this.step;

		const additionalParams = {};

		const assignCommonParams = () => {
			Object.assign(additionalParams, {
				year: this.declareYear,
				...this.otherDatas
			});
		}

		if (this.cPage === 'familyMember') {
			//编辑家庭成员信息
			if (this.editingDataId) {
				Object.assign(additionalParams, {
					id: this.editingDataId
				});
			}
		}
		if (this.cPage === 'childEducation') {
			//添加子女教育信息
			if (currentIndex === 1 && !this.isSubDialogVisible) {
				Object.assign(additionalParams, {
					year: this.declareYear,
				});
				//编辑
				if (this.editingDataId) {
					Object.assign(additionalParams, {
						id: this.editingDataId,
					});
				}
			}
			//完成子女信息填报
			if (currentIndex === 2) {
				assignCommonParams();
			}
		}
		if (['continualEducation', 'loan', 'rent', 'supportOlder'].includes(this.cPage)) {
			assignCommonParams();
			if (this.cPage === 'supportOlder') { //共同赡养人信息
				if (currentIndex === 1 && this.isMainDialogVisible) {
					Object.assign(additionalParams, {
						id: this.editingDataId,
					});
				}
				if (currentIndex === 2) {
					Object.assign(additionalParams, {
						supportParentDatas: JSON.stringify(this.tableEdit.datas),
					});
				}
			}
		}
		if (this.cPage === 'recordInfo') {
			if (this.isSubDialogVisible) {
				if (this.formType === 'personalInfo') {
					Object.assign(additionalParams, {
						id: this.editingDataId,
					});
				}
			} else {
				Object.assign(additionalParams, {
					id: this.editingDataId,
				});
			}
			Object.assign(additionalParams, {
				...this.otherDatas
			});
		}

		return additionalParams;
	}

	//获取顶部按钮组、右键菜单的状态(是否可点击)
	getDisabled = (func) => {
		const {
			loading
		} = this.oneForm, {
			comsWeaTableStore
		} = this.table;

		let b;
		if (['doEdit'].includes(func)) {
			b = loading;
		}
		if (['doCreate'].includes(func)) {
			b = comsWeaTableStore.loading;
		}
		if (['doDelete'].includes(func)) {
			b = comsWeaTableStore.selectedRowKeys.length === 0;
		}
		return b;
	}

	@action handleMenuClick = (type) => {
		if (this.BASICINFOITEMS.includes(type)) {
			this.cPage = type;
		}

		if (type === 'personalInfo') {
			this.operatePersonalForm('0');
		}
		if (type === 'familyMember') {
			this.getRightMenu();
			this.getSearchList();
		}
		if (this.TAXDEDUCTIONITEMS.includes(type)) {
			this.storagePageType(type);
			this.defineDialogTitle(getLabel(505850, '填报前，您需要提前准备以下材料'));
			this.openDialog();
			this.getPreInfo(type);
		}
	}

	//设置即将跳转页面的类型
	storagePageType = (type) => {
		this.temp = type;
	}

	//**********************NoLinkageForm、CollapseForm**********************
	formType = '';

	declareYear = '';

	callFormAPIParams = {}; //调用表单接口所需的参数

	@observable taxType = '';

	@observable useFormType = 'forward';

	@computed get linkage() {
		const {
			currentIndex
		} = this.step;

		const continualEducation = {
			eduLevel: {
				activeKey: 'eduType',
				activeValue: '1',
			},
			startDate: {
				activeKey: 'eduType',
				activeValue: '1',
			},
			endDate: {
				activeKey: 'eduType',
				activeValue: '1',
			},
			devType: {
				activeKey: 'eduType',
				activeValue: '2',
			},
			issueDate: {
				activeKey: 'eduType',
				activeValue: '2',
			},
			certificateNum: {
				activeKey: 'eduType',
				activeValue: '2',
			},
			certificateName: {
				activeKey: 'eduType',
				activeValue: '2',
			},
			issueUnit: {
				activeKey: 'eduType',
				activeValue: '2',
			}
		};

		const supportOlder = {
			cost: {
				activeKey: 'onlyChild',
				activeValue: '1,2'
			},
			costType: {
				activeKey: 'onlyChild',
				activeValue: '2'
			}
		};
		if (this.cPage === 'childEducation') {
			return {
				lastname: {
					activeKey: 'hasSpouse',
					activeValue: '1',
				},
				verificationType: {
					activeKey: 'hasSpouse',
					activeValue: '1',
				},
				verificationId: {
					activeKey: 'hasSpouse',
					activeValue: '1',
				},
				percent: {
					activeKey: 'hasSpouse',
					activeValue: '1,2',
				},
			};;
		}
		if (this.cPage === 'continualEducation') {
			return continualEducation;
		}
		if (this.cPage === 'loan') {
			return {
				lastname: {
					activeKey: 'hasSpouse',
					activeValue: '1',
				},
				verificationType: {
					activeKey: 'hasSpouse',
					activeValue: '1',
				},
				verificationId: {
					activeKey: 'hasSpouse',
					activeValue: '1',
				}
			};
		}
		if (this.cPage === 'rent') {
			if (currentIndex === 1) {
				return {
					lastname: {
						activeKey: 'rentType',
						activeValue: '1',
					},
					verificationType: {
						activeKey: 'rentType',
						activeValue: '1',
					},
					verificationId: {
						activeKey: 'rentType',
						activeValue: '1',
					},
					creditCode: {
						activeKey: 'rentType',
						activeValue: '2',
					},
					orgName: {
						activeKey: 'rentType',
						activeValue: '2',
					}
				};
			}
			if (currentIndex === 2) {
				return {
					lastname: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					},
					verificationType: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					},
					verificationId: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					}
				};
			}
		}
		if (this.cPage === 'supportOlder') {
			return supportOlder;
		}
		if (this.cPage === 'recordInfo') {
			if (this.taxType === '3') { //子女教育
				return {
					spouseLastname: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					},
					spouseVerificationType: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					},
					spouseVerificationId: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					},
					percent: {
						activeKey: 'hasSpouse',
						activeValue: '1,2',
					},
				};
			}
			if (this.taxType === '6') { //住房租金
				return {
					rentLastname: {
						activeKey: 'rentType',
						activeValue: '1',
					},
					rentVerificationType: {
						activeKey: 'rentType',
						activeValue: '1',
					},
					rentVerificationId: {
						activeKey: 'rentType',
						activeValue: '1',
					},
					creditCode: {
						activeKey: 'rentType',
						activeValue: '2',
					},
					orgName: {
						activeKey: 'rentType',
						activeValue: '2',
					},
					spouseLastname: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					},
					spouseVerificationType: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					},
					spouseVerificationId: {
						activeKey: 'hasSpouse',
						activeValue: '1',
					}
				}
			}
			if (this.taxType === '4') { //继续教育
				return continualEducation;
			}
			if (this.taxType === '7') { //赡养老人
				return supportOlder;
			}
		}
	}

	@computed get groupLinkage() {
		const {
			currentIndex
		} = this.step;
		if (this.cPage === 'loan') {
			if (currentIndex === 1) {
				return {
					'1': {
						activeKey: 'loanMode',
						activeValue: '1,3'
					},
					'2': {
						activeKey: 'loanMode',
						activeValue: '2,3'
					}
				}
			}
			if (currentIndex === 2) {
				return {
					'1': {
						activeKey: 'hasSpouse',
						activeValue: '1,2'
					}
				}
			}
		}
		if (this.cPage === 'recordInfo') {
			if (this.taxType === '5') { //住房贷款利息
				return {
					'3': {
						activeKey: 'loanMode',
						activeValue: '1,3'
					},
					'4': {
						activeKey: 'loanMode',
						activeValue: '2,3'
					}
				}
			}
		}
	}

	@observable oneForm = {
		form: new WeaForm(),
		conditions: [],
		loading: false,
		isEdit: '0',
	}

	@observable twoForm = {
		form: new WeaForm(),
		conditions: [],
		loading: false,
	}

	@observable threeForm = {
		form: new WeaForm(),
		conditions: [],
		loading: false,
	}

	@observable fourForm = {
		form: new WeaForm(),
		conditions: [],
		loading: false,
	}

	//表单接口返回的其他数据
	otherDatas = {};

	idCard = '';

	@observable readonly = '0'; //可编辑

	@observable sgHelpfulTip = '';

	@action getForm = (val, callback, specifyWillUseForm) => {
		//设置调用表单接口的参数
		this.setParamsToCallFormAPI(val);

		this.startLoading();

		const willUseForm = specifyWillUseForm ? specifyWillUseForm : this.whichFormWillBeUsed;

		api.getForm(this.cPage, this.callFormAPIParams, this.step.currentIndex, willUseForm, this.formType).then(data => {
			const {
				condition,
				fid,
				id,
				idCard,
				readonly,
			} = data, {
				otherParam,
			} = condition[0];

			if (otherParam && otherParam.helpfulTip) {
				this.sgHelpfulTip = otherParam.helpfulTip;
			} else {
				this.sgHelpfulTip = '';
			}

			//表单上有添加按钮的，在配置数据上添加回调函数。
			if (this.hasAddBtn(condition)) {
				this.addAddBtnEventListener(condition)
			}

			if (!this.isLinkageForm) {
				this.initForm(condition, specifyWillUseForm);
			} else {
				this.initFormOld(condition, specifyWillUseForm);
			}

			if (this.isSingle && willUseForm === 'one') {
				const updateSearchFields = () => {
					const {
						form
					} = this.oneForm;
					form.updateFields(this.query);
				}

				updateSearchFields();
			}

			this.otherDatas = {};

			const addOtherDatas = (datas) => {
				Object.assign(this.otherDatas, datas);
			}

			['id', 'fid', 'costId', 'spouseId'].forEach(v => {
				if (data[v]) {
					addOtherDatas({
						[v]: data[v]
					});
				}
			})

			if (idCard !== undefined) {
				this.idCard = idCard;
			} else {
				this.idCard = '';
			}

			this.readonly = readonly ? readonly : '0';

			callback && callback();

		}, error => {})
	}

	//设置调用表单接口的参数
	setParamsToCallFormAPI = (val) => {
		const {
			currentIndex
		} = this.step;

		//重置callFormAPIParams
		this.callFormAPIParams = {};

		if (this.formType === 'personalInfo') {
			if (val) {
				Object.assign(this.callFormAPIParams, {
					edit: val
				});
			}
			if (this.isSingle) {
				Object.assign(this.callFormAPIParams, {
					pid: this.pid
				});
			}
			return;
		}

		if (['childInfo', 'olderInfo'].includes(this.formType) || ['familyMember', 'recordInfo'].includes(this.cPage)) {
			if (val) {
				if (typeof val === 'string') {
					Object.assign(this.callFormAPIParams, {
						id: val
					});
				} else {
					Object.assign(this.callFormAPIParams, val);
				}
			}
			if (this.formType === 'childInfo') {
				Object.assign(this.callFormAPIParams, {
					rela: 'child'
				});
			}
			if (this.formType === 'olderInfo') {
				Object.assign(this.callFormAPIParams, {
					rela: 'parent'
				});
			}
			return;
		}

		if (this.cPage === 'rent' && currentIndex === 1) {
			Object.assign(this.callFormAPIParams, {
				year: this.declareYear
			});
			return;
		}

		if (['childEducation', 'loan', 'rent', 'supportOlder'].includes(this.cPage) && currentIndex === 2) {
			if (!this.isMainDialogVisible) {
				Object.assign(this.callFormAPIParams, {
					year: this.declareYear
				});
			} else {
				Object.assign(this.callFormAPIParams, {
					rela: 'spouse'
				});
			}
			return;
		}

	}

	@computed get isOneFormInit() {
		return this.oneForm.form.isFormInit;
	}

	@computed get isTwoFormInit() {
		return this.twoForm.form.isFormInit;
	}

	@computed get isThreeFormInit() {
		return this.threeForm.form.isFormInit;
	}

	@computed get isFourFormInit() {
		return this.fourForm.form.isFormInit;
	}

	//判断接下来实例化那个表单，同时用于区分调用那个表单接口。
	@computed get whichFormWillBeUsed() {
		if (this.useFormType === 'forward') {
			if (!this.isOneFormInit) {
				return 'one'
			} else {
				if (!this.isTwoFormInit) {
					return 'two'
				} else {
					if (!this.isThreeFormInit) {
						return 'three'
					} else {
						return 'four'
					}
				}
			}
		} else {
			if (this.isFourFormInit) {
				return 'four';
			} else {
				if (this.isThreeFormInit) {
					return 'three'
				} else {
					if (this.isTwoFormInit) {
						return 'two'
					} else {
						return 'one'
					}
				}
			}
		}
	}

	@computed get currentUsingForm() {
		if (this.isFourFormInit) {
			return 'fourForm';
		}
		if (this.isThreeFormInit) {
			return 'threeForm';
		}
		if (this.isTwoFormInit) {
			return 'twoForm';
		}
		if (this.isOneFormInit) {
			return 'oneForm'
		}
	}

	@action startLoading = () => {
		if (!this.isOneFormInit) {
			this.oneForm.loading = true;
		} else {
			if (!this.isTwoFormInit) {
				this.twoForm.loading = true;
			} else {
				this.threeForm.loading = true;
			}
		}
	}

	@action renewForm = () => {
		if (this.isThreeFormInit) {
			this.threeForm.form = new WeaForm();
		}
		if (this.isTwoFormInit) {
			this.twoForm.form = new WeaForm();
		}
		if (this.isOneFormInit) {
			this.oneForm.form = new WeaForm();
		}
	}

	@action renewCurrentForm = (source) => {
		if (this.isFourFormInit) {
			this.fourForm.form = new WeaForm();
			if (this.cPage === 'recordInfo') {
				if (this.formType === 'personalInfo' && source !== 'close') {
					this.twoForm.form = new WeaForm();
				}
				// if (source !== 'close') {
				// 	this.twoForm.form = new WeaForm();
				// }
			}
			return;
		}
		if (this.isThreeFormInit) {
			this.threeForm.form = new WeaForm();
			if (this.cPage === 'recordInfo') {
				this.twoForm.form = new WeaForm();
			}
			return;
		}
		if (this.isTwoFormInit) {
			this.twoForm.form = new WeaForm();
			return;
		}
		if (this.isOneFormInit) {
			this.oneForm.form = new WeaForm();
		}
	}


	isEdit = (val) => {
		return val === '1'
	}

	hasAddBtn = (conditions) => {
		let b = false;
		conditions && conditions.forEach(c => {
			c.items.forEach(item => {
				const {
					otherParams
				} = item;

				if (otherParams && otherParams.hasAddBtn) {
					b = true;
				}
			})
		});
		return b;
	}

	addAddBtnEventListener = (conditions) => {
		conditions.forEach(c => {
			c.items.forEach(item => {
				const {
					otherParams
				} = item;
				if (otherParams && otherParams.hasAddBtn) {
					item.addOnClick = () => {
						this.defineDialogTitle(getLabel(505845, '新建家庭成员'));
						this.openDialog();
						this.useFormType = 'forward';
						this.getForm();
					}
				}
			});
		});
	}

	initForm = (condition, specifyWillUseForm) => {
		const formName = `${specifyWillUseForm ? specifyWillUseForm : this.whichFormWillBeUsed}Form`;
		this[formName].form.setCondition(condition);
		this[formName].conditions = condition;
		this[formName].loading = false;
	}

	initFormOld = (condition, specifyWillUseForm) => {
		const formName = `${specifyWillUseForm ? specifyWillUseForm :  this.whichFormWillBeUsed}Form`;
		if (this[formName].form.isFormInit) {
			this[formName].form = new WeaForm();
		}
		this[formName].conditions = condition;
		this[formName].form.initFormFields(condition);
		this[formName].loading = false;
	}

	//弹框里渲染的是否为折叠表单
	@computed get isDialogRenderCollapseForm() {
		const {
			currentIndex
		} = this.step;
		if (this.cPage === 'familyMember') {
			const {
				conditions
			} = this.oneForm;
			return conditions.length > 1;
		}
		if (this.cPage === 'childEducation') {
			const formContainterName = (currentIndex === 0) ? 'oneForm' : 'twoForm'
			const {
				conditions
			} = this[formContainterName];

			return conditions.length > 1;
		}
		if (this.cPage === 'recordInfo') {
			return true;
		}
	}

	@computed get isLinkageForm() {
		const {
			currentIndex
		} = this.step;

		if (this.cPage === 'recordInfo') {
			if (this.whichFormWillBeUsed === 'three') {
				return true;
			}
		}

		if (this.cPage === 'childEducation') {
			if (currentIndex === 2 && this.whichFormWillBeUsed === 'one') {
				return true;
			}
		}

		if (this.cPage === 'continualEducation' && currentIndex === 1 && this.whichFormWillBeUsed === 'two') {
			return true;
		}
		if (this.cPage === 'loan') {
			if (currentIndex === 1 && this.whichFormWillBeUsed === 'two') {
				return true;
			}
			if (currentIndex === 2 && this.whichFormWillBeUsed === 'one') {
				return true;
			}
		}
		if (this.cPage === 'rent') {
			if (currentIndex === 1 && this.whichFormWillBeUsed === 'two') {
				return true;
			}
			if (currentIndex === 2 && this.whichFormWillBeUsed === 'one') {
				return true;
			}
		}
		if (this.cPage === 'supportOlder') {
			if (currentIndex === 2) {
				return true
			}
		}

	}

	//控制个人信息表单是否出现下划线
	controlUnderline = (isEdit) => {
		this.oneForm.isEdit = isEdit;
	}

	//监听表单事件
	onFormChange = (datas) => {
		if (datas.hasOwnProperty('year')) {
			this.pageHasTable() && this.getSearchList();
			this.declareYear = datas.year.value;
			if (this.cPage === 'rent') {
				this.useFormType = 'reverse';
				this.formType = '';
				this.getForm();
			}
		}
		if (datas.hasOwnProperty('hasSpouse')) {
			const value = datas.hasSpouse.value;
			this.changePercentFieldState(value);
			if (value === '1') {
				const usingform = this.currentUsingForm;

				const {
					form
				} = this[usingform], {
					lastname,
					spouseLastname,
				} = form.getFormParams();

				const openModal = () => {
					const callback = () => {
						this.defineDialogTitle(getLabel(505845, '新建家庭成员'));
						this.openDialog();
						this.useFormType = 'forward';
						this.formType = '';
						this.getForm();
					}
					this.showConfirm(getLabel(505874, '请填写配偶信息！'), callback);
				}

				if (this.cPage == 'recordInfo') {
					if (!spouseLastname && !this.otherDatas.spouseId) {
						openModal();
					}
				} else {
					if (!lastname && !this.otherDatas.fid) {
						openModal();
					}
				}
			}
		}
		if (datas.hasOwnProperty('onlyChild')) {
			const val = datas.onlyChild.value;
			this.changeDeductionCostFieldState(val);
			if (val === '2') {
				this.getTableEditInfo();
			}
		}
		if (datas.hasOwnProperty('fid')) {
			const id = datas.fid.value;
			this.getBirthday(id);
		}
		if (datas.hasOwnProperty('verificationType')) {
			const usingform = this.currentUsingForm;
			const {
				form
			} = this[usingform], {
				verificationType,
				birthday
			} = form.getFormParams();
			//居民身份证
			if (verificationType === '1') {
				if (!this.idCard) {
					return
				}
				form.updateFields({
					verificationId: {
						value: this.idCard
					},
				});
				if (birthday !== undefined) {
					const birthday = this.extractBirthInfo(this.idCard);
					form.updateFields({
						birthday: {
							value: birthday
						}
					});
				}
			} else { //其他证件
				form.updateFields({
					verificationId: {
						value: ''
					}
				});
				if (birthday !== undefined) {
					form.updateFields({
						birthday: {
							value: ''
						}
					});
				}
			}
		}

	}

	isResidentIdCorrect = false;

	onFormBlur = (value, res, obj) => {
		const isVerificationId = res.hasOwnProperty('verificationId');
		if (isVerificationId) {
			const usingform = this.currentUsingForm;
			const {
				form
			} = this[usingform], {
				verificationType
			} = form.getFormParams();

			const isResidentIdCard = (verificationType === '1');

			if (isResidentIdCard) {
				const isResidentIdCorrect = this.testVerificationId(value);

				this.isResidentIdCorrect = isResidentIdCorrect;

				if (isResidentIdCorrect) {
					const birthday = this.extractBirthInfo(value);

					form.updateFields({
						birthday: {
							value: birthday
						}
					});
				} else {
					message.warning(getLabel(506247, '居民身份证件号不正确！'));
				}
			}
		}
	}

	extractBirthInfo = (verificationId) => {
		const birthStr = verificationId.slice(6, 14);
		const year = birthStr.slice(0, 4);
		const month = birthStr.slice(4, 6);
		const day = birthStr.slice(6);

		return `${year}-${month}-${day}`;
	}

	testVerificationId = (verificationId) => {
		var idcardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;

		if (idcardReg.test(verificationId)) {
			return true;
		}
	}

	testPhone = (phone) => {
		return true; //暂时不校验手机号
		var phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;

		if (phoneReg.test(phone)) {
			return true;
		}
	}

	testEmail = (email) => {
		var emailReg = /(\S)+[@]{1}(\S)+[.]{1}(\w)+/;

		if (emailReg.test(email)) {
			return true;
		}
	}

	@action getBirthday = (id) => {
		api.getFamilyInfo({
			id
		}).then(datas => {
			const {
				personInfo
			} = datas, {
				birthday
			} = personInfo;
			const {
				form
			} = this.twoForm;
			form.updateFields({
				birthday: {
					value: birthday
				}
			});
		});
	}

	//切换字段：本人扣除比例 状态
	@action changePercentFieldState = (value) => {
		const {
			conditions,
			form
		} = this[this.currentUsingForm];

		const isReadOnly = (value === '2');

		conditions.forEach(c => {
			c.items.forEach(item => {
				const {
					domkey
				} = item;

				if (domkey[0] === 'percent') {
					if (isReadOnly) {
						Object.assign(item, {
							viewAttr: 1,
							hasBorder: true,
						});
						form.updateFields({
							percent: '100'
						});
					} else {
						Object.assign(item, {
							viewAttr: 3
						});
						form.updateFields({
							percent: ''
						});
					}

				}
			})
		});
	}

	//切换本年度月扣除金额字段的状态
	@action changeDeductionCostFieldState = (value) => {
		const usingForm = this.currentUsingForm;

		const {
			form,
			conditions,
		} = this[usingForm], {
			onlyChild
		} = form.getFormParams();

		const isReadOnly = (value === '1');

		conditions.forEach(c => {
			c.items.forEach(item => {
				const {
					domkey
				} = item;

				if (domkey[0] === 'cost') {
					if (isReadOnly) {
						Object.assign(item, {
							viewAttr: 1,
							hasBorder: true,
						});
						form.updateFields({
							cost: '2000'
						});
					} else {
						Object.assign(item, {
							viewAttr: 3
						});
						form.updateFields({
							cost: ''
						});
					}

				}
			})
		});
	}

	setNoNeedValidateFields = () => {
		window.e9HideFormFieldKeys = [];

		const {
			currentIndex
		} = this.step;

		const usingForm = this.currentUsingForm;

		const getAllNeedValidateFieldKey = (conditions) => {
			const keys = [];
			conditions.map(c => {
				c.items.map(item => {
					const {
						viewAttr,
						domkey
					} = item;

					if (viewAttr === 3) {
						keys.push(domkey[0])
					}
				});
			});
			return keys
		}

		const getNoNeedValidateKeys = (allKeys, needValidateKeys = []) => {
			const noNeedValidateKeys = allKeys.filter(key => !needValidateKeys.includes(key));
			return noNeedValidateKeys;
		}

		const setConEducationHideFormFieldKeys = () => {
			const {
				eduType
			} = this[usingForm].form.getFormParams();

			if (eduType === '1') {
				window.e9HideFormFieldKeys = ['devType', 'issueDate', 'certificateNum', 'certificateName', 'issueUnit'];
			}
			if (eduType === '2') {
				window.e9HideFormFieldKeys = ['eduLevel', 'startDate', 'endDate'];
			}
		}

		const setLoanHideFormFieldKeys = () => {
			const {
				loanMode
			} = this[usingForm].form.getFormParams();

			if (loanMode === '1') {
				window.e9HideFormFieldKeys = ['bank2', 'contractNum2', 'repayment2', 'loanMonth2'];
			}
			if (loanMode === '2') {
				window.e9HideFormFieldKeys = ['bank1', 'contractNum1', 'repayment1', 'loanMonth1'];
			}
		}

		if (this.cPage === 'childEducation') {
			const {
				hasSpouse
			} = this[usingForm].form.getFormParams();

			if (hasSpouse === '2') {
				window.e9HideFormFieldKeys = ['lastname', 'verificationType', 'verificationId'];
			}

		}

		if (this.cPage === 'continualEducation') {
			setConEducationHideFormFieldKeys();
		}

		if (this.cPage === 'loan') {
			if (currentIndex === 1) {
				setLoanHideFormFieldKeys();
			}
			if (currentIndex === 2) {
				const {
					hasSpouse
				} = this[usingForm].form.getFormParams();
				if (usingForm === 'oneForm') {
					if (hasSpouse === '2') {
						window.e9HideFormFieldKeys = ['lastname', 'verificationType', 'verificationId'];
					}
				}
			}
		}

		if (this.cPage === 'rent') {
			const {
				rentType,
				hasSpouse
			} = this[usingForm].form.getFormParams();
			if (currentIndex === 1) {

				if (rentType === '1') {
					window.e9HideFormFieldKeys = ['orgName', 'creditCode'];
				}
				if (rentType === '2') {
					window.e9HideFormFieldKeys = ['lastname', 'verificationType', 'verificationId'];
				}
			}
			if (currentIndex === 2) {
				if (hasSpouse === '2') {
					window.e9HideFormFieldKeys = ['lastname', 'verificationType', 'verificationId'];
				}
			}
		}

		if (this.cPage === 'supportOlder') {
			if (currentIndex === 2) {
				const {
					conditions,
					form
				} = this.oneForm, {
					onlyChild
				} = form.getFormParams();

				const allValidateKeys = getAllNeedValidateFieldKey(conditions);

				let needValidateKeys;
				if (!onlyChild) {
					needValidateKeys = ['onlyChild'];
				}
				if (onlyChild === '2') {
					needValidateKeys = ['cost', 'costType'];
				}
				window.e9HideFormFieldKeys = getNoNeedValidateKeys(allValidateKeys, needValidateKeys);
			}
		}

		if (this.cPage === 'recordInfo') {
			if (this.taxType === '3') { //子女教育
				const {
					form
				} = this.threeForm, {
					hasSpouse
				} = form.getFormParams();

				if (hasSpouse === '2') {
					window.e9HideFormFieldKeys = ['spouseLastname', 'spouseVerificationType', 'spouseVerificationId'];
				}
			}
			if (this.taxType === '6') { //租房租金
				const {
					form
				} = this.threeForm, {
					rentType,
					hasSpouse,
				} = form.getFormParams();

				if (rentType === '1') {
					['orgName', 'creditCode'].forEach(key => {
						window.e9HideFormFieldKeys.push(key);
					});
				}
				if (rentType === '2') {
					['rentLastname', 'rentVerificationType', 'rentVerificationId'].forEach(key => {
						window.e9HideFormFieldKeys.push(key);
					});
				}
				if (hasSpouse === '2') {
					['spouseLastname', 'spouseVerificationType', 'spouseVerificationId'].forEach(key => {
						window.e9HideFormFieldKeys.push(key);
					})
				}
			}
			if (this.taxType === '4') { //继续教育
				setConEducationHideFormFieldKeys();
			}
			if (this.taxType === '5') { //住房贷款利息
				setLoanHideFormFieldKeys();
			}
		}

	}

	//********************Tab********************
	get buttonsAds(){
		return [getLabel(82529, '搜索'), getLabel(27088, '重置'), getLabel(32694, '取消')];
	}  

	get TAB() {
		return {
		advanceHeight: 130,
		hasMask: false,
		keyParam: 'key',
		setShowSearchAd: this.setShowSearchAd,
		onSearch: this.onSearch,
		onSearchChange: this.onSearchChange,
		onChange: this.onTabChange,
		buttonsAd: this.buttonsAds.map((name, index) => {
			const type = (index === 0) && "primary";
			let callback;
			if (index === 0) {
				callback = () => this.onSearch();
			} else if (index === 1) {
				callback = () => this.oneForm.form.resetConditionValue();
			} else {
				callback = this.setShowSearchAd
			}
			return <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@7xg189@${index}`} type={type} onClick={() => callback(index === 2 && false)}>{name}</Button>
		})
	}
	} 

	@observable tab = {
		showSearchAd: false,
		selectedKey: '0',
		value: ''
	}

	@observable onSearchChange = (val) => {
		if (this.cPage === 'recordInfo') {
			const {
				form
			} = this.oneForm;
			form.updateFields({
				year: val
			});
		} else {
			this.tab.value = val;
		}
	}

	@action onSearch = () => {
		this.getSearchList();

		if (this.tab.showSearchAd) {
			this.setShowSearchAd(false);
		}
	}

	@action onTabChange = (key) => {
		this.tab.selectedKey = key;

		this.setShowSearchAd(false);

		this.renewForm();

		if (this.step.currentIndex !== 0) {
			this.resetStepIndex();
		}

		if (key === '0') { //信息填报
			this.cPage = 'main';
		}
		if (key === '1') { //填报记录查询
			this.cPage = 'recordInfo';
			const callback = () => {
				this.getSearchList();
			}
			this.getForm('', callback)
		}
		if (key === '2') { //扣除金额查询
			this.cPage = 'queryDeductionMoney';
			this.searchCondition.currentKey = '0';
			this.searchCondition.datePickerValue = new Date();
			this.getSearchList();
		}
	}

	@action setShowSearchAd = (b) => {
		this.tab.showSearchAd = b;
	}

	@computed get searchsBaseValue() {
		if (this.cPage === 'recordInfo') {
			const {
				form
			} = this.oneForm;
			return form.getFormParams().year;
		}
		if (this.cPage === 'familyMember') {
			return this.tab.value;
		}
	}

	@computed get tabDatas() {
		if (this.isSingle) {
			return [];
		}
		if (['main', 'recordInfo', 'queryDeductionMoney'].includes(this.cPage)) {
			return [{
				key: '0',
				title: getLabel(505842, '信息填报')
			}, {
				key: '1',
				title: getLabel(505851, '填报记录查询')
			}, {
				key: '2',
				title: getLabel(505852, '扣除金额查询')
			}];
		}
		if (this.cPage === 'familyMember') {
			return [];
		}
	}

	@computed get searchType() {
		const {
			selectedKey
		} = this.tab;

		let type;

		if (['main', 'recordInfo'].includes(this.cPage)) {
			if (selectedKey === '1') {
				type = ['base', 'advanced'];
			}
		}
		if (this.cPage === 'familyMember') {
			type = ['base'];
		}
		return type;
	}
	//*********************Table*********************
	TABLE = {
		hasOrder: true,
		needScroll: true,
	}

	editingDataId = '';

	@observable table = {
		comsWeaTableStore: new TableStore(),
	}

	@action getSearchList = () => {
		const params = this.getParamsToCallTableAPI();

		api.getRecords(this.cPage, params).then(data => {
			const {
				sessionkey,
				helpfulTip,
				grouptitle,
				browserConditionParam
			} = data;

			this.table.comsWeaTableStore = new TableStore();
			this.table.comsWeaTableStore.getDatas(sessionkey, 1);
			if (helpfulTip) {
				this.tableInfoTip = helpfulTip;
			}
			if (grouptitle) {
				this.tableGroupTitle = grouptitle;
			}
			if (browserConditionParam) {
				this.browserConditionParam = browserConditionParam;
			}
		}, error => {})
	}

	getParamsToCallTableAPI = () => {
		const params = {};
		if (this.cPage === 'recordInfo') {
			const {
				form
			} = this.oneForm;

			Object.assign(params, {
				...form.getFormParams()
			});
			if (this.isSingle) {
				Object.assign(params, {
					pid: this.pid
				});
			}
		}
		if (this.cPage === 'familyMember') {
			Object.assign(params, {
				lastname: this.searchsBaseValue
			});
		}
		if (['childEducation', 'supportOlder'].includes(this.cPage)) {
			const {
				form
			} = this.oneForm;

			Object.assign(params, {
				year: form.getFormParams().year
			});
		}
		if (this.cPage === 'queryDeductionMoney') {
			const {
				currentKey,
				datePickerValue
			} = this.searchCondition;

			let date;
			if (currentKey === '0') {
				date = this.formatDate(datePickerValue, true);
			} else {
				date = this.formatDate(datePickerValue, false);
			}

			Object.assign(params, {
				type: (currentKey === '0') ? 'year' : 'month',
				date,
			});
		}
		return params;
	}

	edit = (id, fid, taxType) => {
		if (this.cPage === 'familyMember') {
			this.formType = '';
			this.defineDialogTitle(getLabel(505853, '编辑家庭成员'));
		}
		if (this.cPage === 'childEducation') {
			this.formType = 'childInfo';
			this.defineDialogTitle(getLabel(505854, '编辑子女教育信息'));
		}
		if (this.cPage === 'supportOlder') {
			this.formType = 'olderInfo';
			this.defineDialogTitle(getLabel(505855, '修改家庭成员'));
		}
		if (this.cPage === 'recordInfo') {
			this.defineDialogTitle(getLabel(505856, '填报详情'));
		}
		this.openDialog();
		let editId;
		if (this.cPage === 'supportOlder') {
			editId = fid;
		} else {
			editId = id;
		}
		this.setEditingDataId(editId);
		this.useFormType = 'forward';
		let _id;
		//编辑子女信息需要传fid
		if (this.cPage === 'childEducation') {
			_id = {
				id,
				fid
			}
		} else {
			_id = editId;
		}
		if (this.cPage === 'recordInfo') {
			const callback = () => {
				this.formType = '';
				this.taxType = taxType;
				let param;
				if (this.pid) { //单页
					param = {
						pid: this.pid, //控制表单只读
						id: _id,
					}
				} else {
					param = _id;
				}
				this.getForm(param);
			}
			this.formType = 'personalInfo';
			this.getForm('0', callback)
		} else {
			this.getForm(_id);
		}
	}

	setEditingDataId = (id) => {
		this.editingDataId = id;
	}

	//删除家庭成员
	del = (id) => {
		//删除确认通过后，执行的回调函数
		const callback = () => {
			const params = {
				ids: id
			};

			this.delLogic(params);
		}
		const info = `${getLabel('83877', '确定要删除吗？')}? ${getLabel(505848,'该记录可能会影响已填报信息！')}`;
		this.showConfirm(info, callback);
	}

	abandon = (id) => {
		const callback = () => {
			api.abandon({
				id
			}).then(data => {
				const {
					status
				} = data;

				if (status === '1') {
					message.success(getLabel(505857, '作废成功'));
					this.getSearchList();
				} else {
					message.warning(getLabel(505858, '作废失败'));
				}
			});
		}
		const info = getLabel(505859, '确认作废吗？');
		this.showConfirm(info, callback);
	}

	isEmptyTable = () => {
		const {
			comsWeaTableStore
		} = this.table, {
			datas
		} = comsWeaTableStore;

		return datas.length === 0;
	}

	formatDate = (date, onlyYear) => {
		let pureDate;
		if (!date._d) {
			pureDate = date;
		} else {
			pureDate = date._d;
		}
		const year = pureDate.getFullYear();
		const month = pureDate.getMonth() + 1;
		if (onlyYear) {
			return year
		} else {
			return `${year}-${ (month < 10) ? `0${month}`: month}`
		}
	}

	//*********************Dialog*********************
	DIALOG = {
		hasScroll: true,
		onCancel: () => {
			const callback = () => {
				this.renewCurrentForm('close');
			};
			this.closeDialog(callback);
		},
	}

	@computed get dialogButtons() {
		let btns;
		if (this.cPage === 'main') {
			btns = [
				<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@uxiagi`} type='primary' onClick={() => this.goToDetailPage()}>{getLabel(505860, '准备完毕，进入填报')}</Button>,
				<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@wil6hh`}  onClick={() => this.closeDialog()}>{getLabel(505861, '取消')}</Button>,
			];
		} else {
			btns = (this.readonly === '0') ? [<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@3l7eox`} type='primary' onClick={() => this.saveDialogForm()}>{getLabel(30986, '保存')}</Button>] : [];
		}

		return btns;
	}

	@computed get moreBtn() {
		const btn = {};
		if (this.cPage !== 'main') {
			Object.assign(btn, {
				datas: []
			});
		}

		return btn;
	}

	@computed get icon() {
		let icon;
		if (this.cPage === 'main') {
			icon = 'icon-coms02-Warning'
		} else {
			icon = 'icon-coms-hrm'
		}

		return icon;
	}

	@computed get iconBgcolor() {
		let color;
		if (this.cPage === 'main') {
			color = '#FF9900'
		} else {
			color = '#217346'
		}

		return color;
	}

	@observable dialog = {
		visible: false,
		title: '',
	}

	@observable subDialog = {
		visible: false,
		title: '',
	}

	@action openDialog = () => {
		if (!this.dialog.visible) {
			this.dialog.visible = true;
		} else {
			this.subDialog.visible = true;
		}
	}

	@action closeDialog = (callback) => {
		if (this.subDialog.visible) {
			this.subDialog.visible = false;
		} else {
			this.dialog.visible = false;
		}
		callback && callback();
	}

	@action defineDialogTitle = (title) => {
		if (!this.dialog.visible) {
			this.dialog.title = title;
		} else {
			this.subDialog.title = title;
		}
	}

	//准备完毕、进入填报
	@action goToDetailPage = () => {
		this.cPage = this.temp;
		this.closeDialog();
		this.getRightMenu();
		this.getStep();
		this.formType = 'personalInfo';
		this.useFormType = 'forward';
		//住房贷款利息需要调用两次表单接口
		let callback;
		if (this.cPage === 'loan') {
			callback = () => {
				this.formType = '';
				this.useFormType = 'forward';
				this.getForm();
			}
		}
		this.getForm('0', callback);
	}

	@computed get isSubDialogVisible() {
		return this.subDialog.visible;
	}

	@computed get isMainDialogVisible() {
		return this.dialog.visible;
	}

	getMainDialogLoading = () => {
		if (!this.TAXDEDUCTIONITEMS.includes(this.cPage)) { //当前页面为：家庭成员、个人信息
			return this.oneForm.loading
		} else {
			const {
				currentIndex
			} = this.step;
			if (this.cPage === 'loan' && currentIndex === 2) {
				return this.twoForm.loading;
			}
			if (['loan', 'recordInfo'].includes(this.cPage)) {
				return this.threeForm.loading
			} else {
				return this.twoForm.loading
			}
		}
	}

	getMainDialogFormContainer = () => {
		if (!this.TAXDEDUCTIONITEMS.includes(this.cPage)) {
			return this.oneForm
		} else {
			if (this.cPage === 'loan') {
				const {
					currentIndex
				} = this.step;
				if (currentIndex === 0) {
					return this.threeForm
				} else {
					return this.twoForm;
				}
			} else {
				return this.twoForm
			}
		}
	}

	getSubDialogLoading = () => {
		if (this.cPage === 'childEducation') {
			return this.threeForm.loading;
		}
		if (this.cPage === 'recordInfo') {
			return this.fourForm.loading
		}
	}

	getSubDialogFormContainer = () => {
		if (this.cPage === 'childEducation') {
			return this.threeForm;
		}
		if (this.cPage === 'recordInfo') {
			return this.fourForm
		}
	}

	getDialogStyle = (isMainDialog) => {
		let style;
		if (this.cPage === 'main') {
			style = {
				width: 560,
				height: 235
			}
		}
		if (this.cPage === 'familyMember') {
			style = {
				width: 600,
				height: 350
			}
		}
		if (this.cPage === 'childEducation') {
			style = {
				width: 600,
				height: 500
			};
		}
		if (this.cPage === 'recordInfo') {
			if (isMainDialog) {
				style = {
					width: 600,
					height: 700
				};
			} else {
				style = {
					width: 600,
					height: 350
				}
			}
		}

		return style;
	}

	//**********************PreInfo**********************
	@observable preInfo = [];

	//获取提示信息
	@action getPreInfo = (type) => {
		api.getPreInfo(type).then(data => {
			const {
				items
			} = data;

			items.map((item, index) => {
				Object.assign(item, {
					icon: this.getPreInfoIcon(type, index)
				});
			});

			this.preInfo = items;
		}, error => {})
	}

	//获取提示弹框内的图片地址
	getPreInfoIcon = (type, index) => {
		let icon;
		switch (type) {
			case 'childEducation':
				if (index === 0) {
					icon = <span class="icon-coms02-Educational-information">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>
				} else {
					icon = <span class="icon-coms02-Dependant-information">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>
				}
				break;
			case 'continualEducation':
				icon = <span class="icon-coms02-Educational-information">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>;
				break;
			case 'loan':
				if (index === 0) {
					icon = <span class="icon-coms02-Real-estate-certificate">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>
				} else {
					icon = <span class="icon-coms02-Loan-contract">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>
				}
				break;
			case 'rent':
				if (index === 0) {
					icon = <span class="icon-coms02-Lease-information">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>
				} else {
					icon = <span class="icon-coms02-City-information">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>
				}
				break;
			case 'supportOlder':
				if ([0, 1].includes(index)) {
					icon = <span class="icon-coms02-Dependant-information">
                <span class="path1"></span><span class="path2"></span><span class="path3"></span>
                </span>
				}
				break;
		}
		return icon;
	}

	//校验表单
	//包含两个参数：当前校验表单的类型、校验通过后执行的回调函数
	validateForm = (formType, callback) => {
		this[formType].form.validateForm().then(f => {
			if (f.isValid) {
				callback && callback();
			} else {
				f.showErrors();
			}
		})
	}

	validateMore = (callback) => {
		const {
			currentIndex
		} = this.step;
		if (this.cPage === 'continualEducation' && currentIndex === 1) {
			const {
				form
			} = this.twoForm, {
				issueDate,
				eduType,
			} = form.getFormParams();
			if (eduType === '1') {
				callback && callback();
				return;
			}
			const year = issueDate.split('-')[0];
			if (year !== this.declareYear) {
				message.warning(getLabel(506244, '发证(批准日期)必须在扣除年度'));
			} else {
				callback && callback()
			}
		}
	}

	saveDialogForm = () => {
		const usingForm = this.currentUsingForm;

		//弹框内表单校验通过后，执行的回调函数。
		const callback = () => {
			const result = this.validateCertainField();
			if (!result) {
				return
			}
			this.saveForm(usingForm, (data) => {
				const callback = () => {
					this.renewCurrentForm();
				}
				this.closeDialog(callback);
				//关闭第二个弹框不执行下面的操作
				if (this.isMainDialogVisible) {
					if (this.cPage === 'childEducation') {
						const {
							id,
							name,
							birthday
						} = data;
						const {
							form
						} = this.twoForm;
						form.updateFields({
							fid: {
								value: id,
								valueSpan: name,
								valueObj: [{
									id,
									name
								}]
							}
						});
						form.updateFields({
							birthday: {
								value: birthday
							}
						});
					}
					if (this.cPage === 'recordInfo') {
						if (this.formType === 'personalInfo') {
							this.controlUnderline('0');
							this.getForm('0', '', 'two');
						} else {
							const {
								form
							} = this.threeForm;
							const {
								name,
								verificationId,
								verificationType
							} = data;
							const arr = [name, verificationType, verificationId];
							['spouseLastname', 'spouseVerificationType', 'spouseVerificationId'].forEach((v, i) => {
								form.updateFields({
									[v]: {
										value: arr[i]
									}
								});
							});
						}
					}
					return;
				}
				//判断关闭弹框后是否需要刷新列表
				if (this.isRefreshTable()) {
					this.getSearchList();
				} else { //编辑个人信息
					if (this.cPage === 'rent') {
						this.formType = '';
						this.useFormType = 'reverse';
						this.getForm();
						return;
					}
					this.controlUnderline('0');
					this.formType = 'personalInfo';
					if (this.cPage === 'loan') {
						const {
							currentIndex
						} = this.step;

						if (currentIndex === 2) {
							this.formType = '';
						}
						this.oneForm.form = new WeaForm();
					} else {
						this.useFormType = 'reverse';
					}
					this.getForm('0', '', 'one');
				}
			});
		}

		this.setNoNeedValidateFields();
		this.validateForm(usingForm, callback);
	}

	validateCertainField = () => {
		const usingForm = this.currentUsingForm;

		const {
			form
		} = this[usingForm], {
			verificationId,
			verificationType,
			mobile,
			email,
		} = form.getFormParams();

		const hasVerificationId = (verificationId !== undefined);

		const hasMobile = (mobile !== undefined);

		const hasEmail = email;

		if (hasVerificationId) {
			const isResidentIdCard = (verificationType === '1');
			if (isResidentIdCard) {
				const isResidentIdCorrect = this.testVerificationId(verificationId);
				if (!isResidentIdCorrect) {
					message.warning(getLabel(506247, '居民身份证件号不正确！'));
					return;
				}
			}

		}

		if (hasMobile) {
			if (!this.testPhone(mobile)) {
				message.warning(getLabel(506248, '手机号码不正确！'));
				return;
			}
		}

		if (hasEmail) {
			if (!this.testEmail(email)) {
				message.warning(getLabel(388157, '邮箱格式不正确'));
				return;
			}
		}

		return true;
	}

	//判断保存弹框内表单后，刷新的是列表还是表单。
	isRefreshTable = () => {
		const {
			currentIndex
		} = this.step;

		//保存家庭成员、填报详情
		if (['familyMember', 'recordInfo'].includes(this.cPage)) {
			return true
		}
		//添加子女教育信息、新建家庭成员
		if (['childEducation', 'supportOlder'].includes(this.cPage) && currentIndex === 1) {
			return true
		}

	}

	//**********************Step**********************
	@observable step = {
		currentIndex: 0,
		items: []
	}

	@action getStep = () => {
		api.getStep(this.cPage).then(data => {
			const {
				steps
			} = data;

			steps.map((step, index) => {
				Object.assign(step, {
					status: (index === 0) ? 'process' : 'wait'
				});
			});

			this.step.items = steps;
		}, error => {})
	}

	@action resetStepIndex = () => {
		this.step.currentIndex = 0;
	}


	//*********************Title******************
	modify = () => {
		this.controlUnderline('1');
		this.defineDialogTitle(getLabel(505863, '修改个人信息'));
		this.openDialog();
		this.useFormType = 'forward';
		this.formType = 'personalInfo';
		this.getForm('1');
	}

	//*****************ButtonIcons*****************
	buttonIcons = [{
		buttonType: 'add',
		type: 'primary',
		onClick: () => this.addInfoToTable()
	}, {
		buttonType: 'del',
		type: 'primary',
		onClick: () => this.delInfoFromTable()
	}];

	addInfoToTable = () => {
		//判断扣除年份是否填写
		const isYearEmpty = () => {
			const {
				form
			} = this.oneForm, {
				year
			} = form.getFormParams();

			return !year;
		}
		if (this.cPage === 'childEducation') {
			this.formType = 'childInfo';
			this.defineDialogTitle(getLabel(505864, '添加子女教育信息'));
		}
		if (this.cPage === 'supportOlder') {
			this.formType = 'olderInfo';
			this.defineDialogTitle(getLabel(505845, '新建家庭成员'));
		}
		const isEmpty = isYearEmpty();
		if (isEmpty) {
			message.info(getLabel(505865, '请选择扣除年度'));
			return;
		}
		this.openDialog();
		this.useFormType = 'forward';
		this.setEditingDataId('');
		this.getForm();
	}

	delInfoFromTable = () => {
		this.doDelete();
	}
	//********************TableUnderSearchGroup********************
	@observable tableInfoTip = '';

	@observable tableGroupTitle = '';

	//********************TableEdit********************
	TABLEEDIT = {
		title: getLabel(505866, '共同赡养人信息'),
		showCopy: false,
		ref: ref => this.setRef(ref),
		onChange: datas => {
			this.tableEdit.datas = datas;
		},
		validator: {
			rules: {
				lastname: 'required',
				verificationType: 'required',
				verificationId: 'required',
				nationality: 'required',
			}
		}
	}

	tableEditRef = null;

	@observable tableEdit = {
		columns: [],
		datas: [],
	}

	@action getTableEditInfo = () => {
		const params = {
			costId: this.otherDatas.id,
			year: this.declareYear
		};
		api.getTableEditInfo(params).then(data => {
			['columns', 'datas'].forEach(v => {
				this.tableEdit[v] = data[v];
			});
		}, error => {})
	}

	validateTableDatas = (callback) => {
		const {
			datas
		} = this.tableEdit;
		if (datas.length === 0) {
			message.warning(getLabel(506245, '请填写共同赡养人信息！'));
			return
		}
		if (this.tableEditRef && this.tableEditRef.doValidate().pass) {
			callback && callback();
		}
	}

	setRef = (ref) => {
		this.tableEditRef = ref;
	}

	//********************SearchCondition********************
	@observable searchCondition = {
		datePickerValue: new Date(),
		currentKey: '0',
	};

	get SEARCHCONDITION(){
		return {
		searchConditionTabs: [{
			key: '0',
			title: getLabel(26577, "年")
		}, {
			key: '1',
			title: getLabel(6076, '月')
		}],
		onTabChange: (key) => {
			this.searchCondition.currentKey = key;
			this.getSearchList();
		},
		resetSearchCondition: () => {
			this.searchCondition.currentKey = '0';
			this.searchCondition.datePickerValue = new Date();
			this.getSearchList();
		},
		handleDatePickerChange: (value) => {
			this.searchCondition.datePickerValue = value;
			this.getSearchList();
		}
	}
	} 

	//********************单页配置项********************
	@observable isSingle = false;

	query = {};

	pid = '';

	@action exportQuery = (query) => {
		const {
			year,
			status,
			pid
		} = query;

		if (year) {
			Object.assign(this.query, {
				year
			});
		}
		if (status) {
			Object.assign(this.query, {
				status
			});
		}
		this.pid = pid;

		const isSingle = Object.keys(query).some(key => ['year', 'status', 'pid'].includes(key));

		if (isSingle) { //单页
			this.isSingle = true;
			this.onTabChange('1');
		}
	}


	//********************选择被赡养人浏览按钮********************
	BROWSER = {
		ref: 'browser',
		onChange: datas => {
			const callback = () => this.getSearchList();
			this.saveSupportOlderInfo(datas, callback);
		}
	};

	browserRef = null;

	@observable browserConditionParam = {};

	@action exportBrowserRef = (ref) => {
		this.browserRef = ref;
	}

	multiAdd = () => {
		const {
			form
		} = this.oneForm, {
			year
		} = form.getFormParams();

		if (!year) {
			message.info(getLabel(505865, '请选择扣除年度'));
		} else {
			this.browserRef && this.browserRef.openModal();
		}
	}

	saveSupportOlderInfo = (fid, callback) => {
		api.saveRecords({
			fid,
			year: this.declareYear
		}).then(data => {
			const {
				status
			} = data;
			if (status === '1') {
				callback && callback();
			} else {
				message.warning(data.message);
			}
		}, error => {})
	}

}

export const hrmTax = new HrmTax();